Page({
  data: {
    adminID: [],
    name: ''
  },

  onLoad: function () {
    const db=wx.cloud.database();
    db.collection('admin').where({
       _openid: 'oMr_G5PFfqcEsZPWQhX5qxQ-AjH8'
     }).get({
       success: res => {
         console.log(res)
         this.setData({
           //读取数据库的第一个数据
           password: res.data[0].password,
           //ID: res.data[0].name
         })
         console.log(this.data.password)
       }
     })
  },

  judge(e) {
    console.log(e.detail.value)
    //逻辑还需要完善
     if (e.detail.value == this.data.password) {
       wx.redirectTo({
         url: '../task/task'
       })
     }
    /*wx.cloud.callFunction({
      name: 'checklogin',
      data: {
        name: this.data.name,
        psw: e.detail.value
      },
      
      success: res => {
        console.log(res.result.isok)
        if (res.result.isok) {
          wx.redirectTo({
            url: '../task/task'
          })
        }
      }
    })*/
  },
  input(e) {
    this.setData({
      name: e.detail.value
    })
  },
  authentication: function () {
    wx.cloud.callFunction({
      name: 'login',
      complete: res => {
        db.collection('admin').get().then(res => {
          if (openid === res.data[0].stID) {
            this.setData({
              authority: true
            })
          }
        })
      }
    })
  },
  compare: function (e) {
    if (e.detail.value.user.length == 0) {
      wx.showModal({
        title: '账号为空',
        content: '请输入账号！',
        showCancel: false,
        confirmColor: '#f00'
      })
    } else if (e.detail.value.user.key == 0) {
      wx.showModal({
        title: '密码为空',
        content: '请输入密码！',
        showCancel: false,
        confirmColor: '#f00'
      })
    } else {
      wx.showModal({
        title: '密码错误',
        content: '请重新输入密码！',
        showCancel: false,
        confirmColor: '#f00'
      })
    }
  }
})